//
//  SQMainViewController.m
//  pai
//
//  Created by pro on 14-10-30.
//  Copyright (c) 2014年 linjunjing. All rights reserved.
//

#import "SQMainViewController.h"
#import "SQMainListViewController.h"
#import "SQAuctionViewController.h"
#import "SQMyViewController.h"
#import "SQRechargeViewController.h"
#import "SQLoginViewController.h"
#import "UserInfo.h"
#import "Global.h"

@interface SQMainViewController ()

@end

@implementation SQMainViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    //首页
    SQMainListViewController* first = [[SQMainListViewController alloc]initWithNibName:nil bundle:nil];
    UINavigationController* navFirst = [[UINavigationController alloc]initWithRootViewController:first];
    [first.tabBarItem setImage:[UIImage imageNamed:@"TabBar_3"]];
    [first.tabBarItem setTitle:@"首页"];
    [first.tabBarItem setSelectedImage:[UIImage imageNamed:@"TabBar_3_HL"]];
    
    //竞拍
    //SQAuctionViewController* auction = [[SQAuctionViewController alloc]initWithNibName:nil bundle:nil];
    //UINavigationController* navAution = [[UINavigationController alloc]initWithRootViewController:auction];;
    //[navAution.tabBarItem setImage:[UIImage imageNamed:@"btn14"]];
    //[navAution.tabBarItem setTitle:@"竞拍"];
    //[navAution.tabBarItem setSelectedImage:[UIImage imageNamed:@"btn14_HL"]];
    
    //充值
    self.recharge = [[SQRechargeViewController alloc]initWithNibName:nil bundle:nil];
    self.navRecharge = [[UINavigationController alloc]initWithRootViewController:self.recharge];
    [self.recharge.tabBarItem setImage:[UIImage imageNamed:@"TabBar_2"]];
    [self.recharge.tabBarItem setTitle:@"充值"];
    [self.recharge.tabBarItem setSelectedImage:[UIImage imageNamed:@"TabBar_2_HL"]];
    
    //我的
    self.my = [[SQMyViewController alloc]initWithNibName:nil bundle:nil];
    self.navMy = [[UINavigationController alloc]initWithRootViewController:self.my];
    [self.my.tabBarItem setImage:[UIImage imageNamed:@"TabBar_1"]];
    [self.my.tabBarItem setTitle:@"我的"];
    [self.my.tabBarItem setSelectedImage:[UIImage imageNamed:@"TabBar_1_HL"]];
    
    //self.viewControllers = @[navFirst,navRecharge,self.navMy];
    self.viewControllers = @[navFirst,self.navRecharge,self.navMy];
    [self.tabBar setTintColor:[UIColor colorWithRed:25/255.0 green:159/255.0 blue:229/255.0 alpha:1.0]];
    [self.tabBarController.tabBar setSelectedImageTintColor:[UIColor blueColor]];
    [self.navigationController setNavigationBarHidden:YES animated:NO];
    
    self.delegate = self;
    
    
    [[NSNotificationCenter defaultCenter]  addObserver:self selector:@selector(changebadgeValue:) name:@"ACS_ERR_UNREAD_NOTE" object:nil];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(void)changebadgeValue:(NSNotification*)notification
{
    NSLog(@"ACS_ERR_UNREAD_NOTE");
   //self.my.tabBarItem.badgeValue = @"";
}

- (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
{
    NSLog(@"12312313:%@",viewController);
    if (viewController==self.navMy) {
        //[self.my checkLogin];
        if ([[Global instance] logined]) {
            return YES;
        }
        else
        {
            SQLoginViewController* lvc = [[SQLoginViewController alloc]init];
            [self.my.navigationController pushViewController:lvc animated:YES];
            return YES;
        }
    }else if (viewController==self.navRecharge) {
        //[self.my checkLogin];
        if ([[Global instance] logined]) {
            return YES;
        }
        else
        {
            SQLoginViewController* lvc = [[SQLoginViewController alloc]init];
            [self.recharge.navigationController pushViewController:lvc animated:YES];
            return YES;
        }
    }
    else
    {
        NSLog(@"not my");
    }
    return YES;
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
